<template>

	<div class="common-seach-wrap">
		<!-- <el-tabs v-model="activeName">
			<el-tab-pane name="first">
				<template #label>
					<span>积分设置</span>
				</template>
			</el-tab-pane>
			<el-tab-pane name="second">
				<template #label>
					<span>积分明细</span>
				</template>
			</el-tab-pane>
		</el-tabs> -->

		<!--积分设置-->
		<Setting v-if="activeName == 'first'"></Setting>
		<!--积分明细-->
		<Log v-if="activeName == 'second'"></Log>

	</div>
</template>
<script>
	import Setting from './part/Setting.vue';
	import Log from './part/Log.vue';
	import {
		reactive,
		toRefs,
		defineComponent
	} from 'vue';
	import {
		useUserStore
	} from '@/store';
	export default defineComponent({
		components: {
			Setting,
			Log
		},
		setup() {
			const {
				bus_emit,
				bus_off,
				bus_on
			} = useUserStore();
			const state = reactive({
				bus_emit,
				bus_off,
				bus_on,
				/*是否加载完成*/
				loading: true,
				form: {},
				/*参数*/
				param: {},
				/*当前选中*/
				activeName: 'first',
				/*切换数组原始数据*/
				sourceList: [{
						key: 'first',
						value: '积分设置',
						path: '/user/points/setting'
					},
					{
						key: 'second',
						value: '积分明细',
						path: '/user/points/log'
					}
				],
				/*权限筛选后的数据*/
				tabList: [],
			});
			return {
				...toRefs(state),
			};
		},
		mounted() {
		
			this.tabList = this.authFilter();
		
			if (this.tabList.length > 0) {
				this.activeName = this.tabList[0].key;
			}
		
			if (this.$route.query.type != null) {
				this.activeName = this.$route.query.type;
			}
		
			/*监听传插件的值*/
			this.bus_on('activeValue', res => {
				this.activeName = res;
			});
		
			//发送类别切换
			let params = {
				active: this.activeName,
				list: this.tabList,
				tab_type: 'pointsDetail'
			};
			this.bus_emit('tabData', params);
		
		},
		beforeUnmount() {
			//发送类别切换
			this.bus_emit('tabData', {
				active: null,
				tab_type: 'pointsDetail',
				list: []
			});
			this.bus_off('activeValue');
		},
		methods: {
		
			/*权限过滤*/
			authFilter() {
				let list = [];
				for (let i = 0; i < this.sourceList.length; i++) {
					let item = this.sourceList[i];
					if (this.$filter.isAuth(item.path)) {
						list.push(item);
					}
				}
				return list;
			},
		
		}
	});
</script>

<style>

</style>